<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<head>
    <title>社交平台</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
</head>
<jsp:include page="/views/header.jsp"/>

<div class="container mt-4">
    <div class="row">
        <div class="col-md-3">
            <div class="card">
                <div class="card-header">
                    <h5>好友管理</h5>
                </div>
                <div class="card-body">
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link" href="${pageContext.request.contextPath}/friend/list">好友列表</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="${pageContext.request.contextPath}/friend/requests">好友请求</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="${pageContext.request.contextPath}/friend/search">查找好友</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="col-md-9">
            <div class="card">
                <div class="card-header">
                    <h5>好友请求</h5>
                </div>
                <div class="card-body">
                    <c:if test="${not empty message}">
                        <div class="alert alert-success">${message}</div>
                    </c:if>
                    <c:if test="${not empty error}">
                        <div class="alert alert-danger">${error}</div>
                    </c:if>

                    <c:if test="${empty requests}">
                        <div class="alert alert-info">暂无好友请求</div>
                    </c:if>

                    <ul class="list-group">
                        <c:forEach items="${requests}" var="request">
                            <fmt:formatDate value="${request.createdAt}" pattern="yyyy-MM-dd HH:mm" var="formattedDate"/>
                            <li class="list-group-item">
                                <div class="d-flex justify-content-between align-items-center">
                                    <div class="d-flex align-items-center">
                                        <img src="${pageContext.request.contextPath}${not empty request.user.avatar ? request.user.avatar : '/images/default-avatar.png'}"
                                             class="avatar-sm me-3" alt="用户头像">
                                        <div>
                                            <h6 class="mb-0">${request.user.nickname}</h6>
                                            <small class="text-muted">${formattedDate}</small>
                                        </div>
                                    </div>
                                    <div>
                                        <form action="${pageContext.request.contextPath}/friend/accept" method="post" class="d-inline">
                                            <input type="hidden" name="friendId" value="${request.user.userId}">
                                            <button type="submit" class="btn btn-sm btn-success me-2">接受</button>
                                        </form>
                                        <form action="${pageContext.request.contextPath}/friend/reject" method="post" class="d-inline">
                                            <input type="hidden" name="friendId" value="${request.user.userId}">
                                            <button type="submit" class="btn btn-sm btn-danger">拒绝</button>
                                        </form>
                                    </div>
                                </div>
                            </li>
                        </c:forEach>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<jsp:include page="/views/footer.jsp"/>